<?php

declare(strict_types=1);

namespace App\Common\Service\Affiliate;

use Psr\Container\ContainerInterface;

class AffiliateFactory
{
    protected array $map = [
        'jd'     => JdService::class,
        'pdd'    => PddService::class,
        'taobao' => TaoBaoService::class,
        'wph'    => WphService::class,
    ];

    public function __construct(protected ContainerInterface $container) {}

    public function getService(string $type): AbstractAffiliateService
    {
        if (! isset($this->map[$type])) {
            throw new \InvalidArgumentException("unsupported affiliate type: {$type}");
        }
        /** @var AbstractAffiliateService $svc */
        $svc = $this->container->get($this->map[$type]);
        return $svc;
    }
}